package gipf.trunk;
import java.util.ArrayList;



/**
 * @author eric
 * contains the positions (e.g. 5|5) of placing and moving
 * can create a random move
 */
public class action {
	
	private int player;
	private position placePosition;
	private position movePosition;
	private int takeIndex;
	
	/**
	 * empty action (created by the boardView and adjusted by clicks)
	 */
	public action(){
		
	}

	/**
	 * @param player who performaed the action
	 * also the value stored in the int pieces[], so it might also be not only 1 or 2
	 * but also for example 11 or 12 for gipf pieces 
	 */
	public action(int player){
		this.player = player;		
	}
	
	/**
	 * @param place
	 * set the position of the piece which is to be placed (outter ring)
	 */
	public void setPlace(position place){
		placePosition = place;
	}
	
	/**
	 * @param move
	 * set the position where you want to move a piece (second ring)
	 */
	public void setMove(position move){
		movePosition = move;
	}
	
	
	/**
	 * @param player
	 * used for setting, when not initialized with a player
	 */
	public void setPlayer(int player){
		this.player = player;
	}
	
	/**
	 * @param index
	 * set the index of the line you want to take (not used yet)
	 */
	public void setTakeIndex(int index){
		takeIndex = index;
	}
	
	/**
	 * @return the position on the outter ring
	 */
	public position getPlacePosition(){
		return placePosition;
	}
	
	/**
	 * @return the position on the second ring
	 */
	public position getMovePosition(){
		return movePosition;
	}
	
	/**
	 * @return the index of the line you want to remove
	 */
	public int getTakeIndex(){
		return takeIndex;
	}
	
	/**
	 * @param pieces the current int[] of pieces (used for checking for a full line)
	 * 
	 * creates a random action with a placing position and a moving position
	 */
	public void createRandomMove(int[] pieces){
		int[] allIndexes = {0, 1, 2, 3, 4, 10, 17, 25, 34, 42, 49, 55, 60, 59, 58, 57, 56, 50, 43, 35, 26, 18, 11, 5 };
		
		position p1;
		position p2;
		ArrayList<position> adj;
		do{
			int chooser = (int) (Math.random()*24);
			
			p1 = staticBoard.getPosition(allIndexes[chooser]);
			
			adj = staticBoard.adjFieldsPosition(p1);
			int chooser2 = (int) (Math.random()*adj.size());
			
			p2 = adj.get(chooser2);	
			
	
		}while(staticBoard.lineFull(p1, p2, pieces));
		
		placePosition = p1;
		movePosition = p2;
		
	}
	
	

}
